/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.root;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author kostya
 */
public class Log {
    public static final int LEVEL_DEBUG = 0;
    public static final int LEVEL_INFO = 1;
    public static final int LEVEL_ERROR = 2;
    public static final String[] codes = {"DEBUG", "INFO", "ERROR"};
    private static int maxLevel = LEVEL_DEBUG;
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("d.M-H:mm:ss");


    public static void setMaxLevel(int aMaxLevel){
        maxLevel = aMaxLevel;
    }

    public static void print(int aLevel, Object aReporter, Object... aMessage){
        if(aLevel<maxLevel)
            return;
        StringBuffer buffer = new StringBuffer();
        if(dateFormat!=null)
            buffer.append("["+dateFormat.format(new Date())+"]");
        else
            buffer.append("[]");
        buffer.append("["+codes[aLevel]+"]");
        if(aReporter!=null && aReporter.getClass()!=null)
            buffer.append((aReporter instanceof String)?aReporter:
                aReporter.getClass().getSimpleName());
        else
            buffer.append("STATIC");
        buffer.append(": ");
        for (int i = 0; i < aMessage.length; i++) {
            Object object = aMessage[i];
            buffer.append(object+" ");
        }
        System.err.println(buffer);
    }

    public static void debug(Object aReporter, Object... aMessage){
        print(LEVEL_DEBUG, aReporter, aMessage);
    }

    public static void info(Object aReporter, Object... aMessage){
        print(LEVEL_INFO, aReporter, aMessage);
    }

    public static void error(Object aReporter, Object... aMessage){
        print(LEVEL_ERROR, aReporter, aMessage);
    }
}
